package com.kc.service.Impl;

import com.kc.dao.UserDao;
import com.kc.entity.Teacher;
import com.kc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    // 1. 查询所有数据
    @Override
    public List<Teacher> findall(){
        List<Teacher> list = userDao.findAll();
        return list;
    }

    // 2. 根据id查询
    @Override
    public Teacher finduser(Integer id) {
        Teacher teacher = userDao.findById(id).get();
        return teacher;
    }

    // 3. 增加
    @Override
    public void adduser(Teacher teacher) {
        userDao.save(teacher);
    }

    // 4. 根据id删除
    @Override
    public void removeuser(Integer id) {
        userDao.deleteById(id);
    }

    // 5. 修改数据
    @Override
    public void updateuser(Teacher teacher) {
        userDao.saveAndFlush(teacher);
    }
}
